package edu.controller;

import edu.repository.AuthCodeRepository;
import edu.service.AuthCodeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by shixi  on 2021/1/28
 */
@RestController
@RequestMapping("/code")
public class CodeController {

    @Autowired
    private AuthCodeServiceImpl authCodeService;

    /**
     * ⽣成验证码并发送到对应邮箱，成功true，失败 false
     * @param email
     * @return
     */
    @RequestMapping("/create/{email}")
    public boolean create(@PathVariable(value = "email") String email){
        return authCodeService.createAndSend(email);
    }


    /**
     * 校验验证码是否正确，0正确1错误2超时
     * @param email
     * @param code
     * @return
     */
    @RequestMapping("/validate/{email}/{code}")
    public int validate(@PathVariable(value = "email") String email,
                        @PathVariable(value = "code") String code){
        return authCodeService.validate(email,code);
    }

}